﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IFTRUE.FMS.BLL
{
    /// <summary>
    /// 作用：业务模块公共类
    /// 作者：iftrue
    /// 日期：2013-08-20
    /// </summary>
   public class Common
    {

       /// <summary>
       /// 获取分页游标
        /// </summary>
        /// <param name="collection">要查询的集合</param>
       /// <param name="query">查询条件</param>
       /// <param name="sort">排序条件</param>
        /// <param name="currIndex">当前页索引</param>
        /// <param name="pageSize">页行数</param>
       /// <param name="recordCount">记录总数</param>
       /// <returns></returns>
       public MongoDB.Driver.MongoCursor<T> GetMongoCursorByPage<T>(MongoDB.Driver.MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoSortBy sort,int currIndex, int pageSize,ref long recordCount)
       {
        //目前使用Skip+Limit组合分页，效率较低，在数据量较大时需要重写该方法
           int skip = (currIndex-1) * pageSize;
           recordCount = collection.Count(query);
           MongoDB.Driver.MongoCursor<T> cursor = collection.FindAs<T>(query).SetSortOrder(sort).SetSkip(skip).SetLimit(pageSize);
           return cursor;
       }
    }
}
